package com.heartware.sh.blackhole.ui.fragment.base;

import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.heartware.sh.blackhole.R;
import com.heartware.sh.blackhole.ui.fragment.NullFragment;
import com.heartware.sh.blackhole.ui.fragment.view.LoadingPager;

/**
 * Created by Administrator on 2018/3/26 0026.
 */

public abstract class BaseNullFragment extends BaseFragment {

    private LoadingPager loadingPager;

    protected Handler handler = new Handler();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        if(loadingPager == null){

            loadingPager = new LoadingPager(getContext());

            loadingPager.setLoadingListenter(new LoadingPager.LoadingListenter() {
                @Override
                public void load() {
                    BaseNullFragment.this.load();
                }

                @Override
                public void init() {
                    BaseNullFragment.this.init();
                }
            });
            loadingPager.setSuccessView(createSuccessView());
        }

        show();

        return loadingPager;
    }


    public void show(){

        if(loadingPager != null){
            loadingPager.show();
        }

    }

    public void setState(LoadingPager.LoadingResult result){

        if(loadingPager != null){
            loadingPager.setState(result);
        }

    }


    public abstract void load();

    public abstract void init();


    public abstract View createSuccessView();

    /**
     * 获取资源ID
     * @return
     */
    public int getLayoutId(){
        return 0;
    }

    public View findViewById(@IdRes int id) {
        return loadingPager.findViewById(id);
    }


}
